import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/order/pay-info';


export interface PayInfoParam {
    orderNo?: string;
    memberId?: string;
    tradeChannel?: number;
    status?: number;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface PayInfoResponse {
    id?: number;
    orderId: string;
    orderNo: string;
    memberId?: string;
    totalAmount?: string;
    tradeChannel?: string;
    tradeNo?: string;
    status?: number;
    complatedTime?: string;

    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface PayInfoSaveCommand {
    id?: number;
    orderId: string;
    orderNo: string;
    memberId?: string;
    totalAmount?: string;
    tradeChannel?: string;
    tradeNo?: string;
    status?: number;
    complatedTime?: string;
}

export interface PayInfoResponseList {
    list: PayInfoResponse[];
    total: number;
}


// 通过PayInfoParam参数获取分页列表
export function pagePayInfo(params: PayInfoParam) {
    return axios.get<PayInfoResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取支付信息信息
export function getPayInfo(id: number) {
    return axios.get<PayInfoResponse>(`${BASE_URL}/${id}`);
    
}

export function listPayInfo(params: PayInfoParam) {
    return axios.get<PayInfoResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加支付信息
export function addPayInfo(params: PayInfoSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新支付信息
export function updatePayInfo(params: PayInfoSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除支付信息
export function deletePayInfo(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}

// 切换支付信息状态
export function switchPayInfoStatus(id: number) {
    return axios.patch(`${BASE_URL}/switch/status/${id}`);
}